package com.xwn.utils.core;

import org.apache.commons.io.FileUtils;
import org.apache.http.util.ByteArrayBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Author duandw
 * @Date 2019/12/31 17:30
 **/
public class FileUtilsImpl extends FileUtils {
    private static final Logger logger = LoggerFactory.getLogger(FileUtilsImpl.class);

    public FileUtilsImpl() {
    }

    public void writeFile(byte[] content, String pathFileName) throws IOException {
        FileOutputStream writer = null;

        try {
            writer = new FileOutputStream(pathFileName);
            writer.write(content, 0, content.length);
            writer.flush();
        } finally {
            try {
                if (writer != null) {
                    writer.close();
                }
            } catch (Exception var10) {
                logger.trace(var10.getMessage(), var10);
            }

        }

    }

    public byte[] readFile(String pathFileName) throws IOException {
        FileInputStream read = null;
        byte[] buf = new byte[5120];
        ByteArrayBuffer bb = new ByteArrayBuffer(10240);

        try {
            read = new FileInputStream(pathFileName);

            int len;
            while((len = read.read(buf)) > 0) {
                bb.append(buf, 0, len);
            }

            byte[] var6 = bb.toByteArray();
            return var6;
        } finally {
            try {
                if (read != null) {
                    read.close();
                }
            } catch (Exception var13) {
                logger.trace(var13.getMessage(), var13);
            }

        }
    }
}
